<template>
  <div class="lanjian-content" style="height: 760px;overflow: auto">
    <a-form-model
      ref="ruleForm1"
      :labelCol="labelCol"
      :wrapperCol="wrapperCol"
      :rules="rules"
      class='formbox cusFormBox'
      :model="ruleForm"
    >
      <a-form-model-item label="派驻组评估情况" class='formtabMax'>
        <a-textarea
          style="width: 100%;min-height: 100px"
          v-model:value='ruleForm.pzz_pg_infos'
          placeholder=""
          auto-size
          disabled="true"
          :rows="4"
        />
      </a-form-model-item>
      <a-form-model-item
        label='编辑人'
        class='formtab'
        prop='pzz_editor'
      >
        <a-input
          v-model.trim='ruleForm.pzz_editor'
          placeholder=''
          :maxLength='200'
          disabled="true"
        />

      </a-form-model-item>
      <a-form-model-item
        label='联系电话'
        class='formtab cus'
        prop='pzz_phone'
      >
        <a-input
          v-model.trim='ruleForm.pzz_phone'
          placeholder=''
          :maxLength='200'
          disabled="true"
        />
      </a-form-model-item>

      <a-form-model-item label="监督检查室评估情况" class="formtabMax">
        <a-textarea
          style="width: 100%;min-height: 100px"
          v-model.trim:value="ruleForm.jdjcs_pg_infos"
          placeholder=""

          disabled="true"
          autoSize
        />
      </a-form-model-item>
      <a-form-model-item
        label='编辑人'
        class='formtab'
        prop='jdjcs_editor'
      >
        <a-input
          v-model.trim='ruleForm.jdjcs_editor'
          placeholder=''
          :maxLength='200'
          disabled="true"

        />
      </a-form-model-item>
      <a-form-model-item
        label='联系电话'
        class='formtab cus'
        prop='jdjcs_phone'
      >
        <a-input
          v-model.trim='ruleForm.jdjcs_phone'
          placeholder=''
          :maxLength='200'
          disabled="true"
        />
      </a-form-model-item>
        <a-form-model-item
          label='领导意见'
          class='formtabMax'
        >
          <a-textarea
            style="width: 100%;min-height: 100px"
            v-model:value='ruleForm.ldyj'
            placeholder=""
            auto-size
            disabled="true"
            :rows="4"
          />
        </a-form-model-item>
        <a-form-model-item label="附件">
          <ui v-for="item in ruleForm.fafj">
            <li><a @click="downtmp(item.tfpath,item.tfname)">{{ item.tfname }}</a></li>
          </ui>
        </a-form-model-item>
    </a-form-model>
  </div>
</template>
<script>
import { getuploadFileInfo, addRectificationPlan, getRectificationPlanTotal, streamToBuffer } from '@/utils/JsonTools';
import UploadPlus from '@/components/UploadPlus/index.vue';
import { getLDType } from '@/utils/common';
import fs from 'fs';

export default {
  name: 'Total',
  components: { UploadPlus },
  data() {
    return {
      disble: false,
      jdjcs_ldyj: '',
      mulite: false,
      // 表单标题内容宽度设置
      labelCol: { span: 24 },
      wrapperCol: { span: 24 },
      ruleForm: {},
      // 表单规则
      rules: {
        fileList: [{ required: true, message: '请上传文件', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
        editor: [{ required: true, message: '请输入编辑人', trigger: 'blur' }],
      },
      fileList: [],
    };
  },
  mounted() {
    this.getInfos();
  },
  methods: {
    // 上传验证
    beforeFileUpload(file) {
      if (file.name.substring(0, file.name.indexOf('.')).length > 200) {
        this.$message.error('上传文件名字不得超过200字');
        return false;
      }
      let isLt2M = file.size / 1024 / 1024;
      if (isLt2M > 200) {
        this.$message.error('只允许上传200M以下的文件');
        return false;
      }
      let fileExt = file.name.slice(file.name.lastIndexOf('.') + 1);
      let fileTypeArr = ['doc', 'docx', 'pdf', 'xls', 'xlsx', 'jpg', 'png', 'jpeg', 'txt', 'ext'];
      if (fileTypeArr.indexOf(fileExt) === -1) {
        this.$message.error('非法的文件类型');
        return false;
      }
      return true;
    },
    handleRemove() {
      this.ruleForm.fileList = [];
    },
    customUpload(file) {
      // beforeFileUpload()返回为true，才会触发这个方法；
      this.handleUpload(file);
    },
    // 构造formData
    handleUpload(file) {
      // const formData = new FormData()
      // let timestamp = new Date().getTime()
      // formData.append('files', file)
      // formData.append('fileUid', file.uid)
      // formData.append('totalBytes', file.size)
      // formData.append('time', timestamp)
      // this.imagerAdd(formData)
      getuploadFileInfo(file.file).then(res => {
        file.onSuccess(res);
        // eslint-disable-next-line no-unused-expressions
        this.$nextTick(() => {
          this.ruleForm.fileList = [];
          this.ruleForm.fileList.push(res);
        });

        // this.save()
      });
    },
    getInfos() {
      getRectificationPlanTotal().then(res => {
        console.log('pp--', res);
        this.fileList = res===undefined?[]:res.fileList;
        this.ruleForm = res;
        if ((res.f_status == '1' || res.f_status == '4')&&res!=undefined) {
          this.disble = true;
        }
      });
    },
    save() {
      this.$refs.ruleForm1.validate(valid => {
        // eslint-disable-next-line eqeqeq

        if (valid) {
          this.ruleForm.plan_status = 0;
          addRectificationPlan(this.ruleForm).then(res => {
            if (res === 0) {
              this.$message.error('保存失败');
              return;
            }
            this.$message.success('保存成功');
          });
        }
      });
    },
    downtmp(path, name) {
      let fileb = fs.createReadStream(path);
      let fsname = name;
      console.log('fsname-----' + fsname);
      streamToBuffer(fileb).then(res => {
        let data = res;
        let contents = new Uint8Array(data.length);
        for (let i = 0; i < data.length; i++) {
          contents[i] = data[i];
        }
        // eslint-disable-next-line no-undef
        let expname = fsname;
        saveAs.saveAs(new Blob([contents], { type: 'application/zip' }), expname);
      });
    },
  },
};
</script>
<style scoped lang="less">
/deep/ .ant-form-item-label {
  width: 176px;
}

/deep/ .ant-input {
  width: 260px
}
</style>
<style lang="scss">
// 滚动条背景颜色
.ant-form::-webkit-scrollbar,
.info::-webkit-scrollbar {
  height: 9px;
  width: 9px;
  background-color: #fcfcfc;
}

// 滚动条颜色
.ant-form::-webkit-scrollbar-thumb,
.info::-webkit-scrollbar-thumb {
  border-radius: 9px;
  background-color: #000000;
}

.ant-form-item label{
  font-weight: bold;
}

</style>
